<!--模板 html-->
<template>
  <div>
    <!--按钮 html-->
    <div class="tab_btns">
        <el-button type="primary" size="small" @click="toFormHandler">新增</el-button>
    </div>

    <!--表格 html-->
    <div class="tab_content">
      <el-table :data="category" style="width: 100%">

      <el-table-column
        prop="id"
        label="序号"
        width="180">
      </el-table-column>

      <el-table-column
        prop="name"
        label="名称"
        width="180">
      </el-table-column>

      <el-table-column
        prop="description"
        label="描述"
        width="180">
      </el-table-column>

       <el-table-column
        prop="no"
        label="no"
        width="180">
      </el-table-column>

       <el-table-column
        prop="parentId"
        label="父ID">
      </el-table-column>
       <!-- 操作列 -->
        <el-table-column width="100" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="editHandler(scope.row)">修改</el-button>
            <el-button type="text" @click="deleteHandler(scope.row)">删除</el-button>
          </template>
        </el-table-column>
    </el-table>

    </div>
  </div>
</template>

<!--脚本 js-->
<script>
import  {del, get} from '@/utils/request'
export default {
  //定义变量，在模板中直接用
    data(){
        return {
            category:[],
            visible:false
        }
    },
    //定义事件处理函数、方法
    methods:{
      // 删除的处理函数
        deleteHandler(row){
          this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        type: 'warning'
        }).then(() => {
          let url = "http://localhost:8888/category/deleteById"
            del(url,{id:row.id}).then(resp =>{
              // 1. 提示
              this.$message({type:"success",message:resp.message});
              // 2. 刷新
              this.loadcategory();
            })
            
          })
      },
        editHandler(row){
          this.$router.push({ 
            path:"/chenmeifang/categoryform",
            query:row
          })
        },
        // 跳转到温室大棚录入页面
        toFormHandler(){
          // 跳转
          this.$router.push({ path:"/chenmeifang/categoryform" })
        },


        //查询所有数据
        loadcategory(){
            let url = "http://localhost:8888/category/query"
            get(url).then(resp => {
                //获取数据后做的事情
                this.category = resp.data;
            })
        }
    },
    //生命周期钩子函数
    created(){
        this.loadcategory();
    }

}
</script>


<!--css 样式-->
<style lang="sass" scoped>

</style>
